package com.rdgzs.framework.exception;

public class BaseCheckedException extends Exception {

	private int resCode;

	private String exceptionStackInfo;

	private String exceptionContent;

	private Throwable rootCause;

	public BaseCheckedException(int resCode) {
		super();
		this.resCode = resCode;
	}
	
	public BaseCheckedException(String exceptionContent) {
		super(exceptionContent);
		this.exceptionContent = exceptionContent;
	}
	
	public BaseCheckedException(int resCode, String exceptionContent) {
		super(exceptionContent);
		this.resCode = resCode;
		this.exceptionContent = exceptionContent;
	}
	
	public BaseCheckedException(String exceptionContent, Throwable ex) {
		super(exceptionContent, ex);
		this.exceptionContent = exceptionContent;
		this.rootCause = ex;
		parseExceptionStackInfo(rootCause);
	}

	public BaseCheckedException(int resCode, String exceptionContent, Throwable ex) {
		super(exceptionContent, ex);
		this.resCode = resCode;
		this.exceptionContent = exceptionContent;
		this.rootCause = ex;
		parseExceptionStackInfo(rootCause);
	}

	public int getResCode() {
		return this.resCode;
	}

	public void setResCode(int resCode) {
		this.resCode = resCode;
	}
	
	public String getExceptionStackInfo() {
		return exceptionStackInfo;
	}

	public void setExceptionStackInfo(String exceptionStackInfo) {
		this.exceptionStackInfo = exceptionStackInfo;
	}

	public String getExceptionContent() {
		return exceptionContent;
	}

	public void setExceptionContent(String exceptionContent) {
		this.exceptionContent = exceptionContent;
	}

	public Throwable getRootCause() {
		return rootCause;
	}

	public void setRootCause(Throwable rootCause) {
		this.rootCause = rootCause;
	}

	private void parseExceptionStackInfo(Throwable ex) {
		if (ex == null) {
			return;
		}
		StringBuffer sb = new StringBuffer();
		sb.append(ex.getClass().getName()).append(":").append(ex.getMessage()).append("\r\n");
		StackTraceElement stack[] = ex.getStackTrace();
		for (int i = 0; i < stack.length; i++) {
			sb.append("\t").append(stack[i]).append("\r\n");
		}
		exceptionStackInfo = sb.toString();
	}

}
